package leecode

func flatten(root *TreeNode) {
	dummyHead := &TreeNode{}
	//先序遍历
	var dfs func(root *TreeNode)
	dfs = func(node *TreeNode) {
		if node == nil {
			return
		}
		//暂存节点
		left, right := node.Left, node.Right
		//左右节点只想空
		node.Left, node.Right = nil, nil
		dummyHead.Right = node
		dummyHead = dummyHead.Right
		dfs(left)
		dfs(right)
	}
	dfs(root)
	root = dummyHead.Right
}
